package logic

import (
	"context"
	"zhihu/models/mysql"
	"zhihu/zhihuRpc/internal/svc"
	"zhihu/zhihuRpc/zhihuRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type QuestionAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQuestionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QuestionAddLogic {
	return &QuestionAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QuestionAddLogic) QuestionAdd(in *zhihuRpc.QuestionAddRequest) (*zhihuRpc.QuestionAddResponse, error) {
	// todo: add your logic here and delete this line

	question := mysql.Question{
		UserId:  in.UserId,
		Content: in.Content,
	}

	mysql.DB.Create(&question)

	return &zhihuRpc.QuestionAddResponse{
		Id: int64(question.ID),
	}, nil
}
